<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>微信聊天界面</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      margin: 0;
      padding: 0;
      background-color: #f5f5f5;
    }
    .chat-container {
      display: flex;
      flex-direction: column;
      height: 100vh;
      max-width: 600px;
      margin: 0 auto;
      border: 1px solid #ddd;
      background-color: #fff;
    }
    .chat-header {
      padding: 10px;
      background-color: #08c;
      color: #fff;
      text-align: center;
      font-size: 18px;
    }
    .chat-messages {
      flex: 1;
      overflow-y: auto;
      padding: 10px;
    }
    .message {
      margin-bottom: 10px;
      max-width: 70%;
    }
    .message.sent {
      align-self: flex-end;
      background-color: #dcf8c6;
      border-radius: 10px 10px 0 10px;
    }
    .message.received {
      align-self: flex-start;
      background-color: #fff;
      border-radius: 10px 10px 10px 0;
      border: 1px solid #ddd;
    }
    .message p {
      margin: 0;
      padding: 10px;
      font-size: 14px;
      word-break: break-word;
    }
    .chat-input {
      display: flex;
      border-top: 1px solid #ddd;
      padding: 10px;
      background-color: #f9f9f9;
    }
    .chat-input textarea {
      flex: 1;
      resize: none;
      border: 1px solid #ddd;
      border-radius: 5px;
      padding: 10px;
      font-size: 14px;
    }
    .chat-input button {
      margin-left: 10px;
      background-color: #08c;
      color: #fff;
      border: none;
      padding: 10px 20px;
      border-radius: 5px;
      cursor: pointer;
      font-size: 14px;
    }
    .chat-input button:hover {
      background-color: #005f8a;
    }
  </style>
</head>
<body>
<div class="chat-container">
  <div class="chat-header">微信聊天界面</div>
  <div class="chat-messages" id="chatMessages">
    <div class="message received">
      <p>你好！</p>
    </div>
    <div class="message sent">
      <p>你好！有什么可以帮你的吗？</p>
    </div>
  </div>
  <div class="chat-input">
    <textarea id="messageInput" rows="1" placeholder="输入消息..."></textarea>
    <button onclick="sendMessage()">发送</button>
  </div>
</div>
<script>
  function sendMessage() {
    const input = document.getElementById('messageInput');
    const message = input.value.trim();
    if (message) {
      const messageContainer = document.createElement('div');
      messageContainer.className = 'message sent';
      const messageContent = document.createElement('p');
      messageContent.textContent = message;
      messageContainer.appendChild(messageContent);

      document.getElementById('chatMessages').appendChild(messageContainer);
      input.value = '';
      input.focus();

      // 滚动到底部
      const chatMessages = document.getElementById('chatMessages');
      chatMessages.scrollTop = chatMessages.scrollHeight;
    }
  }
</script>
</body>
</html>
